﻿<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register assembly="GenericDataLayer" namespace="DataLayer.Generic" tagprefix="DataLayer" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Literal ID="litError" runat="server"></asp:Literal>
        <DataLayer:GenericObjectDataSource ID="ProductDataSource" runat="server" EnablePaging="true" SortParameterName="sortExpression" 
            OnUpdated="ProductDataSource_Updated"
            OnInserted="ProductDataSource_Updated"
            DataObjectTypeName="DataLayer.Product" 
            TypeName="DataLayer.ProductStaticRepository" 
            />
        <DataLayer:GenericObjectDataSource ID="CategoryDataSource" runat="server" 
            TypeName="DataLayer.CategoryStaticRepository"/>
        <asp:GridView ID="GridView1" runat="server" DataKeyNames="ProductId" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="False" 
            DataSourceID="ProductDataSource" >
            <Columns>
                <asp:BoundField DataField="ProductID" HeaderText="ProductID" 
                    SortExpression="ProductID" />
                <asp:BoundField DataField="ProductName" HeaderText="ProductName" 
                    SortExpression="ProductName" />
                <asp:BoundField DataField="SupplierID" HeaderText="SupplierID" 
                    SortExpression="SupplierID" />
                <asp:TemplateField HeaderText="Category" SortExpression="Category.CategoryName">
                    <ItemTemplate><asp:Label runat="server" ID="CategoryLabel" Text='<%# Eval("Category.CategoryName") %>'></asp:Label></ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList runat="server" ID="CategoryDropDownList" DataTextField="CategoryName" DataValueField="CategoryId" SelectedValue='<%# Bind("CategoryID") %>' DataSourceID="CategoryDataSource">
                        </asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>    
                <asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" 
                    SortExpression="QuantityPerUnit" />
                <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" 
                    SortExpression="UnitPrice" />
                <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" 
                    SortExpression="UnitsInStock" />
                <asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" 
                    SortExpression="UnitsOnOrder" />
                <asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" 
                    SortExpression="ReorderLevel" />
                <asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" 
                    SortExpression="Discontinued" />
                <asp:HyperLinkField Text="View" DataNavigateUrlFields="ProductId" DataNavigateUrlFormatString="~/view.aspx?ProductId={0}" />
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="true" />
            </Columns>
        </asp:GridView>
    
    </div>
    <asp:FormView ID="FormView1" runat="server" DataSourceID="ProductDataSource" DataKeyNames="ProductID"
        DefaultMode="Insert">
        <InsertItemTemplate>
            ProductName:
            <asp:TextBox ID="ProductNameTextBox" runat="server" 
                Text='<%# Bind("ProductName") %>' />
            <br />
            SupplierID:
            <asp:TextBox ID="SupplierIDTextBox" runat="server" 
                Text='<%# Bind("SupplierID") %>' />
            <br />
            Category:
            <asp:DropDownList runat="server" ID="CategoryDropDownList" DataTextField="CategoryName" DataValueField="CategoryId" SelectedValue='<%# Bind("CategoryID") %>' DataSourceID="CategoryDataSource">
            </asp:DropDownList>
            <br />
            QuantityPerUnit:
            <asp:TextBox ID="QuantityPerUnitTextBox" runat="server" 
                Text='<%# Bind("QuantityPerUnit") %>' />
            <br />
            UnitPrice:
            <asp:TextBox ID="UnitPriceTextBox" runat="server" 
                Text='<%# Bind("UnitPrice") %>' />
            <br />
            UnitsInStock:
            <asp:TextBox ID="UnitsInStockTextBox" runat="server" 
                Text='<%# Bind("UnitsInStock") %>' />
            <br />
            UnitsOnOrder:
            <asp:TextBox ID="UnitsOnOrderTextBox" runat="server" 
                Text='<%# Bind("UnitsOnOrder") %>' />
            <br />
            ReorderLevel:
            <asp:TextBox ID="ReorderLevelTextBox" runat="server" 
                Text='<%# Bind("ReorderLevel") %>' />
            <br />
            Discontinued:
            <asp:CheckBox ID="DiscontinuedCheckBox" runat="server" 
                Checked='<%# Bind("Discontinued") %>' />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                CommandName="Insert" Text="Insert" />
            &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </InsertItemTemplate>
    </asp:FormView>
    </form>
</body>
</html>
